import {ADD, REQUEST_BEGIN, REQUEST_SUCCESS, REQUEST_FAIL} from './constants'

let defaultState = {
  count: 0,
  name: 'cai',
  isLoading: false,
  err: {errCode: 0, errMsg: undefined }
}
export default function reducers(state = defaultState, action) {
  console.log("state ===> ", state)
  console.log("action ===> ", action)
  switch (action.type) {
    case ADD:
      return {
        ...state,
        count: state.count + action.val
      }
    case REQUEST_BEGIN:
      return {
        ...state,
        isLoading: true
      }
    case REQUEST_SUCCESS:
      return {
        ...state,
        data: action.data,
        isLoading: false,
        err: {errCode: 0, errMsg: ''}
      }
    case REQUEST_FAIL:
      return {
        ...state,
        err: {errCode: action.err[0], errMsg: action.err[1]},
        isLoading: false
      }
    default:
      return state
  }
  
}